package com.eshop.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.eshop.bean.GoodsBean;

public class ProductDetailsDao {

	private Connection conn = null;
	private PreparedStatement sta = null;
	private ResultSet r = null;
	
	public ArrayList<GoodsBean> productDetails(Integer goods_id)
	{
		
		 conn = Conn.getConn();
		 String sql = "select * from goods where goods_id = ?";
		 ArrayList<GoodsBean> goodsinformation = new ArrayList<GoodsBean>();
		 try {

			 sta =  conn.prepareStatement(sql);
			 sta.setObject(1, goods_id);
			 r = sta.executeQuery();
			 while(r.next())
			 {
				 Integer goodsId =  r.getInt("goods_id");
				 Integer brandsId = r.getInt("brands_id");
				 Integer adminsId = r.getInt("admins_id");
				 String goodsName = r.getString("goods_name");
				 String goodsImg =  r.getString("goods_img");
				 Float goodsPrice = r.getFloat("goods_price");
				 Integer goodsStock = r.getInt("goods_stock");
				 String goodsDescription = r.getString("goods_description");
				 Integer goodsStatus = r.getInt("goods_status");
				 Integer goodsExist = r.getInt("goods_exist");
				 String goodsRemark = r.getString("goods_remark");
				 
				 GoodsBean goodsBean = new GoodsBean();
				 goodsBean.setGoodsId(goodsId);
				 goodsBean.setBrandsId(brandsId);
				 goodsBean.setAdminsId(adminsId);
				 goodsBean.setGoodsName(goodsName);
				 goodsBean.setGoodsImg(goodsImg);
				 goodsBean.setGoodsPrice(goodsPrice);
				 goodsBean.setGoodsDescription(goodsDescription);
				 goodsBean.setGoodsStatus(goodsStatus);
				 goodsBean.setGoodsExist(goodsExist);
				 goodsBean.setGoodsStock(goodsStock);
				 goodsBean.setGoodsRemark(goodsRemark);
				 
				 goodsinformation.add(goodsBean);
			 } 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				if(r != null)
				{
					r.close();
				}
				if(sta != null)
				{
					sta.close();
				}
				if(conn != null)
				{
					conn.close();
				}
	} catch (SQLException e) {
		e.printStackTrace();
		
	}
}		
		return goodsinformation;
	}
	
}
